//
//  CZWelcomeViewController.swift
//  weibo
//
//  Created by 丁蒙 on 16/6/27.
//  Copyright © 2016年 丁蒙. All rights reserved.
//

import UIKit

class CZWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        
    }
    // MARK - 添加动画
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        //更改约束
        iconImageView.snp_updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
        }
        //添加动画
        UIView.animateWithDuration(3, delay: 0.5, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.view.layoutIfNeeded()
            }) { (_) in
                UIView.animateWithDuration(0.5, animations: {
                    
                    self.welcomeLabel.alpha = 1.0
                    
                    }, completion: { (_) in
                        //发送通知 切换控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(switchNotice, object: nil)
                })
        }
    }
    // MARK - 添加子控件
    private func setupUI() {
        view.addSubview(iconImageView)
        view.addSubview(welcomeLabel)
        // MARK - 添加约束
        iconImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(400)
            make.size.equalTo(CGSize(width: 90, height: 90))
        }
        welcomeLabel.snp_makeConstraints { (make) in
            make.top.equalTo(iconImageView.snp_bottom).offset(16)
            make.centerX.equalTo(view)
        }
    }
    // MARK - 懒加载控件
    //头像
    private lazy var iconImageView:UIImageView = {
        let imagString = CZUserAccountTools.sharedUserAccountTools.userAccount?.avatar_large
       let url = NSURL(string: imagString!)
        let icon = UIImageView()
        icon.sd_setImageWithURL(url)
        icon.layer.cornerRadius = 45
        icon.layer.masksToBounds = true
        icon.layer.borderColor = ThemeColor.CGColor
        icon.layer.borderWidth = 3
        return icon
    }()
    //welcomeLabl
    private lazy var welcomeLabel: UILabel = {
        let lab: UILabel = UILabel(fontSize: 18, textColor: UIColor.lightGrayColor())
        lab.text = "欢迎回来"
        lab.textAlignment = .Center
        lab.alpha = 0.0
        return lab
    }()
    
    //背景view
    private lazy var bgImageView:UIImageView = UIImageView(imagName: "ad_background")
    
}
